package com.kunlun.basedata.limit.controller;

import com.kunlun.basedata.limit.model.po.AuthorizePo;
import com.kunlun.basedata.limit.model.po.CorrelatePo;
import com.kunlun.basedata.limit.model.vo.UserRelateVo;
import com.kunlun.basedata.limit.service.IAuthorizeService;
import com.kunlun.common.model.Page;
import com.kunlun.common.utils.ResponseUtil;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/authorize")
public class AuthorizeController {

    private Logger log = LogManager.getLogger();

    @Autowired
    private IAuthorizeService authorizeService;

    @RequestMapping(value = "/getAuthorizePage", method = RequestMethod.GET)
    public Object getAuthorizePage(CorrelatePo correlatePo, int currentPage, int pageSize) {
        try {
            Page list = authorizeService.getAuthorizePage(correlatePo, currentPage, pageSize);
            return ResponseUtil.successResponse(list);
        } catch (Exception e) {
            log.error("AuthorizeController getAuthorizePage Error: ", e);
            return ResponseUtil.failedResponse("查询部门人员分派失败！", e.getMessage());
        }
    }

    @RequestMapping(value = "/addAuthorize", method = RequestMethod.POST)
    public Object addAuthorize(AuthorizePo authorizePo) {
        try {
            authorizeService.addAuthorize(authorizePo);
            return ResponseUtil.successResponse("成功");
        } catch (Exception e) {
            log.error("AuthorizeController addAuthorize Error: ", e);
            return ResponseUtil.failedResponse("查询部门人员分派失败！", e.getMessage());
        }
    }

    @RequestMapping(value = "/getAuthorizeByUser", method = RequestMethod.GET)
    public Object getAuthorizeByUser(String tenantId, String appId, String userId) {
        try {
            UserRelateVo userRelateVo = authorizeService.getAuthorizeByUser(tenantId, appId, userId);
            return ResponseUtil.successResponse(userRelateVo);
        } catch (Exception e) {
            log.error("AuthorizeController getAuthorizePage Error: ", e);
            return ResponseUtil.failedResponse("查询部门人员分派失败！", e.getMessage());
        }
    }
}
